#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
string s;
bool is_hui(int i, int j)
{
	if (j - i	== 1) {
		if (s[i] == s[j]) {
			return 1;
		}
	}
	for (int k = i; k <= j; k++) {
		if (s[k] != s[j--]) {
			return 0;
		}
	}
	return 1;
}
int hui(int i, int j)
{
	return j - i + 1;
}
int main()
{
	cin >> s;
	int x = 0;
	int y = 0;
	int mi = 1100000;
	for (int i = 0; i < s.size(); i++) {
		for (int j = i + 1; j < s.size(); j++) {
			if (is_hui(i, j)) {
				int len = hui(i, j);
				mi = min(mi, len);
				x = i;
				y = j;
			}
		}
	}
	if (mi == 1100000) {
		cout << -1 << endl;
	}
	else {
		cout << mi << endl;
	}
	return 0;
}